<template>
  <el-menu
    router
    :default-active="activeIndex"
    >
    <!-- 登陆者为admin -->
    <template v-if="userType == 'admin'">
			<el-menu-item index="/home">
				<i class='el-icon-tickets'></i>
				 <span>数据报表</span>
				</el-menu-item>
      <el-submenu index="1">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>题库管理</span>
        </template>
        <el-menu-item index="/home/questClass">题目分类</el-menu-item>
        <el-menu-item index="/home/questList">题目列表</el-menu-item>
        <el-menu-item index="/home/labellist">标签列表</el-menu-item>
      </el-submenu>
      <el-submenu index="2">
        <template slot="title">
          <i class="el-icon-menu"></i>
          <span>试卷管理</span>
        </template>
        <el-menu-item index="/home/testClass">试卷分类</el-menu-item>
        <el-menu-item index="/home/testList">试卷列表</el-menu-item>
      </el-submenu>
      <el-submenu index="3">
        <template slot="title">
          <i class="el-icon-menu"></i>
          <span>考试管理</span>
        </template>
        <el-menu-item index="/home/preExamName">考试名称预设</el-menu-item>
        <el-menu-item index="/home/examList">考试列表</el-menu-item>
      </el-submenu>
      <el-submenu index="4">
        <template slot="title">
          <i class="el-icon-menu"></i>
          <span>练习管理</span>
        </template>
        <el-menu-item index="/home/practiceList">练习列表</el-menu-item>
      </el-submenu>
      <el-submenu index="5">
        <template slot="title">
          <i class="el-icon-menu"></i>
          <span>个人中心</span>
        </template>
        <el-menu-item index="/home/myExamList">我的考试</el-menu-item>
        <el-menu-item index="/home/myPracticeList">我的练习</el-menu-item>
        <el-menu-item index="/home/myInfo">个人信息</el-menu-item>
        <el-menu-item index="/home/myResetPsw">更改密码</el-menu-item>
      </el-submenu>
       <el-submenu index="6">
        <template slot="title">
          <i class="el-icon-menu"></i>
          <span>人员管理</span>
        </template>
       <el-menu-item index="/home/depManage">用户管理</el-menu-item>
       <el-menu-item index="/home/userTagList">工作角色</el-menu-item>
			 <el-menu-item index="/home/userVisitor">访客管理</el-menu-item>
			 <el-menu-item index="/home/userContract">承包商管理</el-menu-item>
      </el-submenu>
    </template>
    <!-- 登陆者为非admin -->
    <el-submenu v-else index="5">
      <template slot="title">
        <i class="el-icon-menu"></i>
        <span>个人中心</span>
      </template>
      <el-menu-item index="/home/myExamList">我的考试</el-menu-item>
      <el-menu-item index="/home/myPracticeList">我的练习</el-menu-item>
      <el-menu-item index="/home/myInfo">个人信息</el-menu-item>
      <el-menu-item index="/home/myResetPsw">更改密码</el-menu-item>
    </el-submenu>
    <span class="version">version: {{appVersion}}</span>
  </el-menu>
</template>

<script>
export default {
  name: 'LeftNav',
  data () {
    return {
      userType: '',
      activeIndex: '/home',
      appVersion: ''
    }
  },
  beforeMount () {
    let userinfo = JSON.parse(window.localStorage.getItem('userinfo'))
    if (!userinfo) {
      this.$message.error({
        message: `未登录`,
        onClose: () => {
          this.$router.replace('/')
        }
      })
    } else {
      this.userType = userinfo.type
      if (this.userType != 'admin') {
        this.activeIndex = '/home/myExamList'
        this.$router.replace('/home/myExamList')
      } else {
        this.activeIndex = '/home'
      }
    }
    this.appVersion = APP.VERSION
  }
}
</script>

<style>
/* .el-menu{height: 100% !important;} */
.version {
  display: block;
  padding-left: 20px;
  font-size: 14px;
  margin-top: 10px;
  margin-bottom: 10px;
  color: #7b7878;
}
</style>
